import Vue from 'vue'

import QMessage from './src/main.vue';

// 创建构造器
var q_mesageBox = Vue.extend(QMessage);

let instance;

const QMessageBox = function(opts, callback) {
	// 创建实例
	instance = new q_mesageBox({
		el: document.createElement('div')
	});
	// 默认设置
	let o = {
		parentDom: document.body,									// 父级容器
		appendToBody: true,											// 是否将内容插入到body
		title: '提示',												// 标题
		message: '',												// 消息正文
		type: '',													// 类型
		dialogClass: '',											// 自定义弹框类名
		cancelButtonText: '取消',									// 取消按钮的文本内容
		confirmButtonText: '确定',									// 确定按钮的文本内容
		isCenter: false,											// 内容是否居中显示
		showClose: true,											// 是否显示关闭按钮
		isOnly: true,												// 是否只存在一个框
		showCancelButton: false,									// 是否显示取消按钮
		showConfirmButton: true,									// 是否显示确认按钮
	};
	// 用户设置
	if(opts) {
		if(opts.parentDom != undefined) {
			o.parentDom = opts.parentDom;
			o.appendToBody = false;
		}
		if(opts.title != undefined) o.title = opts.title;
		if(opts.message != undefined) o.message = opts.message;
		if(opts.type != undefined) o.type = opts.type;
		if(opts.dialogClass != undefined) o.dialogClass = opts.dialogClass;
		if(opts.cancelButtonText != undefined) o.cancelButtonText = opts.cancelButtonText;
		if(opts.confirmButtonText != undefined) o.confirmButtonText = opts.confirmButtonText;
		if(opts.center != undefined) o.isCenter = opts.center;
		if(opts.showClose != undefined) o.showClose = opts.showClose;
		if(opts.isOnly != undefined) o.isOnly = opts.isOnly;
		if(opts.showCancelButton != undefined) o.showCancelButton = opts.showCancelButton;
		if(opts.showConfirmButton != undefined) o.showConfirmButton = opts.showConfirmButton;
	}
	// 对象合并
	Object.assign(instance, o);
	// 挂载到元素上
	o.parentDom.appendChild(instance.$el);
}



export default QMessageBox;
export { QMessageBox }
